package com.example.Aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.Method;

@Aspect
@Component
public class MyLogAspect {

//   @Resource
//    private RedisTemplate<String,Object> redisTemplate;
//   @Before("@annotation(com.example.Aop.MyAnnotation)")
//    public void beforeAddMethod(JoinPoint joinPoint) throws Throwable{
//       MethodSignature methodSignature=(MethodSignature) joinPoint.getSignature();
//       Method method= methodSignature.getMethod();
//       MyAnnotation myAnnotation=method.getAnnotation(MyAnnotation.class);
//       if(myAnnotation!=null){
//           String Key= myAnnotation.key();
//           redisTemplate.opsForValue().set(Key,null);
//       }
//   }
    @Resource
    private RedisTemplate<String,Object> redisTemplate;
    @Before("@annotation(com.examole.Aop.MyAnnotation)")
    public  void beforeAddMethod(JoinPoint joinPoint) throws Throwable{
        MethodSignature methodSignature=(MethodSignature) joinPoint.getSignature();
        Method method= methodSignaturn.getMethod;
        MyAnnotation myAnnottation=method.getAnnotation(MyAnnotation.class);
        if ((myAnnottation!=null)){
            String Key= myAnnottation.key();
            redisTemplate.opsForValue().set(key,null);
        }
    }
}
